package cn.haoxsf.app.config.init;

import cn.haoxsf.app.common.constant.config.ConstantConfig;
import cn.haoxsf.app.common.util.ToolUtil;
import cn.haoxsf.app.config.wechat.WxAccountConfig;
import cn.haoxsf.app.system.entity.Config;
import cn.haoxsf.app.system.entity.ConfigData;
import cn.haoxsf.app.system.entity.ConfigGroup;
import cn.haoxsf.app.system.service.IConfigService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: app
 * @description: 系统常量初始化
 * @author: Ele qvbanfm@qq.com
 * @create: 2020-04-03 16:25
 **/
@Component
@Log4j2
public class InitConstant {
    @Autowired
    private IConfigService configService;
    @PostConstruct
    public void run(){
        initWx();
    }
    private void initWx() {
        String wxConfigValue = configService.getOne(new QueryWrapper<Config>().eq("config_key", "wx")).getConfigValue();
        if(ToolUtil.isNotEmpty(wxConfigValue)){
            WxAccountConfig wxAccountConfig = JSON.parseObject(wxConfigValue, WxAccountConfig.class);
            ConstantConfig.setConstant("wx",wxAccountConfig);
            log.info("执行微信初始化完成[{}]", ConstantConfig.getConstant("wx"));
        }
    }

}
